﻿var isCanSave = false;
Ext.define('HIT.controller.ReportController', {
	extend : 'Ext.app.Controller',
	models : [ 'Report' ],
	stores : [ 'Report' ],
	views : [ 'ReportUserDefineGrid','ReportAddWin','ReportEditWin','ReportViewPanel' ],
	
	init : function(application) {
		//创建出的过滤条件id
		var myId = 1;
		/*当报告编辑页面中另存为按钮点击后判断是保存还是另存为flag
		 * 当需要编辑自己的报告时编辑页面中保存按钮不可用，点击另存为之后
		 * 次flag+1，执行保存操作保存完成-1*/
		var saveoredit = 0;
		//报告所属者flag
		var owner = 0;
		//新建过滤条件位置参数
		var position = 1;
		
		function checkFieldProperty(tablename, field, id, inputvalue) {
			if ((tablename == null || tablename == '') 
					|| (field == null || field == '') 
					|| (inputvalue == null || inputvalue == '')) {
				return;
			}
			/**
			 * 验证输入的值是否与字段属性匹配
			 * 1，获取当前字段的属性；
			 * 2，取得当前输入的值；
			 */ 
			var islegal = false;
			
			Ext.Ajax.request({
				// 从controller返回的response中读取数据
				url : 'getFieldProperty',
				method : 'POST',
				params : {
					tablename : tablename,
					field : field,
					inputvalue : inputvalue
				},
				async : false,
				success : function(response) {
					s = response.responseText;
					
					json = Ext.JSON.decode(s);
					if (json.resultcode == '0') {
						islegal = json.islegal;
					}
				}
			});
			return islegal;
		}
		
		//检查报告添加页面控件是否为空
		function checknull() {
			var aaa = Ext.getCmp('report-table').getValue();
			var bbb = Ext.getCmp('report-name').getValue();
			var ccc = Ext.getCmp('table_field').getValue();
			var ddd = Ext.getCmp('user').getValue();
			if(aaa == null || aaa == '') {
				return 1;
			} else if (bbb == null || bbb == '') {
				return 2;
			} else if (ccc == null || ccc == '') {
				return 3;
			} else if (ddd == null || ddd == '') {
				return 4;
			} else {
				return 0;
			}
		}
		//编辑时添加过滤条件的函数
		function addcondition(){
			myId++;
			var t_name = Ext.getCmp('filter_field1').getStore();
			var newField = new Ext.form.Panel({
				id : 'fieldset' + myId,
				layout : "hbox",
				border : false,
				items : [{
					xtype : "combo",
					id : 'filter_field' + myId,
					width : 180,
					msgTarget : 'side',
					editable: false,
					valueField : 'value',
                    displayField : 'value',
                    store : t_name,
                    listeners : {
                    	change : function(e) {
                    		Ext.getCmp('filter_value' + e.id.substr(12, e.id.length)).focus();
                    	}
                    }
				},{
					xtype : "combo",
					x : 181,
					width : 80,
					editable: false,
					id : 'operator' + myId,
					msgTarget : 'side',
					valueField : 'value',
					displayField : 'text',
					store: new Ext.data.JsonStore({
						proxy: { 
	    	                type: 'ajax', 
	    	                url : ctx + '/getComboData',
	    	                params:{},
	    	                reader: { 
	    	                    type: 'json', 
	    	                    totalProperty: '', 
	    	                    root: '' 
	    	                } 
	    	             }, 
	    	            fields:['text','value'], 
	    	            autoLoad:true 
			        }),
			        listeners : {
			        	beforerender:function(){
			        		this.store.removeAll();
			        		this.store.on('beforeload', function(store) {
			        			Ext.apply(store.proxy.extraParams , {
			        				type : 'reportadd'
			        			});
			        		});
			        		this.store.load();
			        	}
			        }
				}, {
					xtype : "textfield",
					id : 'filter_value' + myId,
					regex : /^[A-Za-z0-9\u4e00-\u9fa5]+$/,
					regexText : Share.T('过滤条件值只能输入数字，汉字，字母，下划线，中划线。'),
					msgTarget : 'side',
					x : 262,
					width : 130,
					listeners : {
						blur : function (e, evn, eOpts) {
							var id = e.id;
							var i = id.substr(12, id.length);
							
							var inputvalue = e.value;
							var tablename = Ext.getCmp('report-table').getValue();
							var field = Ext.getCmp('filter_field' + i).getValue();
							var islegal = checkFieldProperty(tablename, field, id, inputvalue);
							
							if (!islegal) {
								Ext.getCmp(id).markInvalid(Share.T('请输入合法值。'));
								isCanSave = false;
							} else {
								e.clearInvalid();
								isCanSave = true;
							}
						}
					}
				}, {
					xtype : 'button',
					id : 'filter_del' + myId,
					width : 50,
					x : 408,
					text : Share.T('删除'),
					onClick : function() {
						var ids = this.getId();
						ids = ids.substring(ids.length - 1, ids.length);
						Ext.getCmp('filter_del' + ids).setVisible(false);
						Ext.getCmp('filter_value' + ids).setVisible(false);
						Ext.getCmp('operator' + ids).setVisible(false);
						Ext.getCmp('filter_field' + ids).setVisible(false);
					}
				}]
			});
			Ext.getCmp('filter_condition').insert(position, newField);
			position++;
			Ext.getCmp('filter_condition').doLayout();  
		}
		
		this.control({
			"button" : {
				click : function(button, e, options) {
					if (button.id == 'deal_report-add') {// 添加弹出tab
						myId = 1;
						position = 1;
						var aliasName = 'widget.reportaddpanel';
						var panelid = 'panel-' + aliasName.split('.')[1];
					    var panel = Ext.create(aliasName, {id : panelid});
					    var winid = 'win-' + aliasName.split('.')[1];
						var win = Ext.create('Ext.window.Window', {
			                id        : winid,
			                title 	  : Share.T('报告添加'),
			                resizable : true,
			                closable  : true,
			                width 	  : 700,
			                height    : window.screen.height - 250,
			                y         : 50,
			                layout    : 'fit',
			                plain     : true,
			                modal 	  : true,
			                items     : panel,
			                buttons   : [{
			                            text : Share.T('保存'),
			    						id : 'report-edit-save',
			    						width : 70
			                        }, {
			                            text : Share.T('取消'),
			                            handler : function() {
			                                win.close();
			                            }
			                        }]
			            }).show();
					}else if(button.id == 'deal_report-delete'){//删除
						var grid = Ext.getCmp('tab-report-report');
						if (grid == undefined) {
							return;
						}
						var selModel = grid.getSelectionModel();
						var row=selModel.getSelection();
						if (selModel.hasSelection()) {
							Ext.MessageBox.confirm(Share.T('提示'),Share.T('是否确认删除？'),function(btn){
								if(btn == 'yes'){
									var model = selModel.getSelection();
									var report_hid = [];
									//删除多个
				                	for(var i = 0; i < model.length; i++){
				                		report_hid.push(model[i].get('report_hid'));
				                    }
									Share.AjaxRequest({
										url : ctx + '/ReportDelete',
										params : {
											report_hid : report_hid.join(",")
										},
										callback : function(json) {
											if (json.resultcode == '0') {
												Ext.getCmp('tab-report-report').getStore().reload();
												//修改删除数据刷新数量
		            							var toolbar = Ext.getCmp('ReportUserDefinetoolbar');
		                                        var fromRecord = toolbar.getPageData().fromRecord;
		                                        var toRecord = toolbar.getPageData().toRecord;
		                                        if((toRecord-fromRecord+1)==row.length){
		                                        	toolbar.movePrevious();
		                                        }
		                                        Share.ShowMessage('I0006','删除');
											} else if(json.resultcode == '1') {
												Share.ShowMessage('E0033');
											}else{
												Share.ShowMessage('I0007','删除');
											}
										}
									});
								}
							});
						}else{
							Share.ShowMessage('I0008');
							return;
						}
					}
					//左上编辑按钮
					else if(button.id == 'deal_report-edit'){//编辑弹出tab
						position = 1;
						myId = 1;
						var grid = Ext.getCmp('tab-report-report');
						if (grid == undefined) {
							return;
						}
						var selModel = grid.getSelectionModel();
						if (selModel.hasSelection()) {
							if (selModel.getCount() != 1) {
								Share.ShowMessage('I0009','修改');
								return;
							}else{
								//由share.js中转移出的创建窗口的方法，因需求右下角按钮有不同不能通过share文件创建窗口
								var aliasName = 'widget.reporteditpanel';
								var panelid = 'panel-' + aliasName.split('.')[1];
							    var panel = Ext.create(aliasName, {id : panelid});
							    var winid = 'win-' + aliasName.split('.')[1];
								var win = Ext.create('Ext.window.Window', {
					                id        : winid,
					                title 	  : Share.T('报告编辑'),
					                resizable : true,
					                closable  : true,
					                //定宽动态高
					                width 	  : 700,
					                height    : window.screen.height - 250,
					                y         : 50,
					                layout    : 'fit',
					                plain     : true,
					                modal 	  : true,
					                items     : panel,
					                buttons   : [{
					                            text : Share.T('保存'),
					    						id : 'report-edit-edit',
					    						width : 70
					                        }, {
					                            text : Share.T('另存为'),
					    						id : 'report-edit-saveas',
					    						width : 70
					                        }, {
					                            text : Share.T('取消'),
					                            handler : function() {
					                                win.close();
					                            }
					                        }]
					            }).show();
								var model = selModel.getSelection()[0];
								var report_hid = model.get('report_hid');
								Share.AjaxRequest({
									url : ctx + '/ReportEdit',
									params : {
										report_hid : report_hid
									},
									callback : function(json) {
										Ext.getCmp('report-table').setDisabled(true);
										owner = json.resultcode;
										/*根据过滤条件数新建下拉框 并给其赋值*/
										//后台接受filter_condition字段
										var filter_condition = json.filter_condition;
										//第一次先用分号分为数组
										var splitone = [];
										//第二次用逗号拆分数组
										var splittwo = [];
										//给过滤条件赋值的参数
										var filter_field = '';
										var operator = '';
										var filter_value = '';
										//给过滤条件添加数字id
										var i = 1;
										if(filter_condition == ''){
											if(!json.resultcode == '0'){
												Ext.getCmp('filter_field1').setDisabled(true);
												Ext.getCmp('operator1').setDisabled(true);
												Ext.getCmp('filter_value1').setDisabled(true);
											}
										}else {
											//如果包含分号
											if(filter_condition.contains(";")){
												splitone = filter_condition.split(";");
												for (var int = 0; int < splitone.length; int++) {
													splittwo = splitone[int].split(",");
													filter_field = splittwo[0];
													operator = splittwo[1];
													filter_value = splittwo[2];
													//当前台选择包含时会在数据库中存入 % 回显到前台需将%去掉
													if(filter_value.contains("%")){
														filter_value = filter_value.replace("'%", "");
														filter_value = filter_value.replace("%'", "");
													}else{
														filter_value = filter_value.replace("'", "");
														filter_value = filter_value.replace("'", "");
													}
													/*页面中第一个过滤条件为设定的filter_field1，
													 * addcondition()函数新建条件控件时是从filter_field1开始所以当i为1时不新建控件*/
													if (i > 1) {
														addcondition();
													};
													Ext.getCmp('filter_field' + i).setValue(filter_field);
													Ext.getCmp('operator' + i).setValue(operator);
													Ext.getCmp('filter_value' + i).setValue(filter_value);
													//resultcode为0时说明不是自己创建的报告
													if (!json.resultcode == '0') {
														Ext.getCmp('filter_field' + i).setDisabled(true);
														Ext.getCmp('operator' + i).setDisabled(true);
														Ext.getCmp('filter_value' + i).setDisabled(true);
														Ext.getCmp('filter_del' + i).setDisabled(true);
														if (i > 1) {
															Ext.getCmp('filter_del' + i).setDisabled(true);
														}
													}
													i++;
												}
											}
											//如果不包含分号
											else{
												splittwo = filter_condition.split(",");
												filter_field = splittwo[0];
												operator = splittwo[1];
												filter_value = splittwo[2];
												if(filter_value.contains("%")){
													filter_value = filter_value.replace("'%", "");
													filter_value = filter_value.replace("%'", "");
												}else{
													filter_value = filter_value.replace("'", "");
													filter_value = filter_value.replace("'", "");
												}
												/*当不包含分号时说明只有一个过滤条件，直接赋值*/
												Ext.getCmp('filter_field1').setValue(filter_field);
												Ext.getCmp('operator1').setValue(operator);
												Ext.getCmp('filter_value1').setValue(filter_value);
												if(!json.resultcode == '0'){
													Ext.getCmp('filter_field1').setDisabled(true);
													Ext.getCmp('operator1').setDisabled(true);
													Ext.getCmp('filter_value1').setDisabled(true);
													Ext.getCmp('filter_del1').setDisabled(true);
												}
											}
										}
										
										Ext.getCmp('report-table').setValue(json.name);
										Ext.getCmp('report-name').setValue(json.report_name);
										Ext.getCmp('report-describe').setValue(json.report_describe);
										var store = Ext.getCmp('filter_field1').getStore();
										store.on('beforeload', function(store) {
						         			Ext.apply(store.proxy.extraParams , {
						         				                                 t_name : json.name
						         				                                 });
										});
										store.load();
										Ext.getCmp('table_field').setValue(json.table_field);
										Ext.getCmp('user').setValue(json.user_id);
										
										if (!json.resultcode == '0') {
											//控制页面中控件当非当前用户创建报告时不可用
											Ext.getCmp('report-edit-edit').setDisabled(true);
											Ext.getCmp('report-table').setDisabled(true);
											Ext.getCmp('report-name').setDisabled(true);
											Ext.getCmp('report-describe').setDisabled(true);
											Ext.getCmp('table_field').setDisabled(true);
											Ext.getCmp('user').setDisabled(true);
											Ext.getCmp('getusergroup').setDisabled(true);
											Ext.getCmp('addbtn').setDisabled(true);
										}
									}
								});
							}
						} else {
							Share.ShowMessage('I0008');
							return;
						}
					}
					//报告编辑另存为按钮
					else if (button.id == 'report-edit-saveas') {
						if (owner == 0) {
							//另存为按钮不可用
							Ext.getCmp('report-edit-saveas').setDisabled(true);
							Share.ShowMessage('I0048');
							saveoredit++;
						} else {
							Ext.getCmp('report-edit-edit').setDisabled(false);
							Ext.getCmp('report-table').setDisabled(false);
							Ext.getCmp('report-name').setDisabled(false);
							Ext.getCmp('report-describe').setDisabled(false);
							for(var i = 1; i <= myId; i++){
								Ext.getCmp('filter_field' + i).setDisabled(false);
								Ext.getCmp('operator' + i).setDisabled(false);
								Ext.getCmp('filter_value' + i).setDisabled(false);
								Ext.getCmp('filter_del' + i).setDisabled(false);
							};
							for(var i = 2; i <= myId; i++){
								Ext.getCmp('filter_del' + i).setDisabled(false);
							}
							Ext.getCmp('table_field').setDisabled(false);
							Ext.getCmp('user').setDisabled(false);
							Ext.getCmp('getusergroup').setDisabled(false);
							Ext.getCmp('addbtn').setDisabled(false);
							Ext.getCmp('report-edit-saveas').setDisabled(true);
							 
							saveoredit++;
						}
					}
					//保存按钮
					else if (button.id == 'report-edit-save') {//报告添加保存按钮
						if (!isCanSave) {
							return;
						}
						if (!Ext.getCmp('report-all-info').getForm().isValid()) {
							return;
						}
						//表名
						var table_name = Ext.getCmp('report-table').getValue();
						//模板名称
						var report_name = Ext.getCmp('report-name').getValue();
						//报告描述
						var report_describe = Ext.getCmp('report-describe').getValue();
						//过滤条件
						var filter_condition = '';
						//遍历过滤条件
						for(var i = 1; i <= myId; i++) {
							//判断过滤条件是否隐藏
							var flag = Ext.getCmp('filter_field' + i).isVisible();
							//过滤字段
							var filterfield = Ext.getCmp('filter_field' + i).getValue() == null ? '' : Ext.getCmp('filter_field' + i).getValue();
							//运算符
							var filteroperator = Ext.getCmp('operator' + i).getValue() == null ? '' : Ext.getCmp('operator' + i).getValue();
							//过滤值
							var filtervalueval = Ext.getCmp('filter_value' + i).getValue();
							if(flag){
								if (!filterfield == '' && !filteroperator == '' && !filtervalueval == ''){
									var filtervalue = '';
									//当过滤条件选择包含时直接在数据库中存入like，方便报告查看使用
									if (filteroperator == 'like') {
										filtervalueval = "'%" + filtervalueval + "%'";
									} else {
										filtervalueval = "'" + filtervalueval + "'";
									}
									filtervalue += filtervalueval;
									if (i > 1) {
										filter_condition += ';';
									}
									filter_condition += filterfield + ',' +  filteroperator + ',' + filtervalue;
								} else if (!filterfield == '' && filteroperator == '' && filtervalueval == '') { // 1
									Ext.getCmp('operator' + i).markInvalid(Share.T('此项目不能为空。'));
									Ext.getCmp('filter_value' + i).markInvalid(Share.T('此项目不能为空。'));
									return;
								} else if (!filterfield == '' && !filteroperator == '' && filtervalueval == '') { // 2
									Ext.getCmp('filter_value' + i).markInvalid(Share.T('此项目不能为空。'));
									return;
								} else if (!filterfield == '' && filteroperator == '' && !filtervalueval == '') { // 3
									Ext.getCmp('operator' + i).markInvalid(Share.T('此项目不能为空。'));
									return;
								} else if (!filteroperator == '' && filterfield == '' && filtervalueval == '') { // 4
									Ext.getCmp('filter_field' + i).markInvalid(Share.T('此项目不能为空。'));
									Ext.getCmp('filter_value' + i).markInvalid(Share.T('此项目不能为空。'));
									return;
								} else if (!filteroperator == '' && filterfield == '' && !filtervalueval == '') { // 5
									Ext.getCmp('filter_field' + i).markInvalid(Share.T('此项目不能为空。'));
									return;
								} else if (!filtervalueval == '' && filterfield == '' && filteroperator == '') { // 6
									Ext.getCmp('filter_field' + i).markInvalid(Share.T('此项目不能为空。'));
									Ext.getCmp('operator' + i).markInvalid(Share.T('此项目不能为空。'));
									return;
								} else if (filterfield == '' && filteroperator == '' && filtervalueval == ''){
									continue;
								}
							}else{
								continue;
							}
						}
						if(filter_condition.substring(0,1) == ';'){
							filter_condition = "\"" + filter_condition.substring(1,filter_condition.length) + "\"";
						}else{
							filter_condition = "\"" + filter_condition + "\"";
						}
						//判断无过滤条件是将filter_condition赋值为空
						if(Ext.getCmp('filter_field1').getValue() == null || Ext.getCmp('filter_field1').getValue() == ''){
							filter_condition = null;
						}
						//显示字段
						var table_field = "\"";
						table_field += Ext.getCmp('table_field').getValue();
						table_field += "\"";
						var user_id = "\"";
						user_id += Ext.getCmp('user').getValue();
						user_id += "\"";
						eee = checknull();
						if(eee == 1) {
							Share.ShowMessage('I0010','模板视图');
						} else if (eee == 2) {
							Share.ShowMessage('I0010','模板名称');
						} else if (eee == 3) {
							Share.ShowMessage('I0010','查询字段');
						} else if (eee == 4) {
							Share.ShowMessage('I0010','用户');
						} else if (eee == 0) {
							Share.AjaxRequest({
								url : ctx + '/ReportEditSave',
								params : {
									table_name : table_name,
									report_name : report_name,
									report_describe : report_describe,
									filter_condition : filter_condition,
									table_field : table_field,
									user_id : user_id
								},
								callback : function(json) {
									if (json.resultcode == '0') {
										Ext.getCmp('win-reportaddpanel').close();
										Share.ShowMessage('I0006', '保存');
										Ext.getCmp('tab-report-report').getStore().reload();
									}else{
										Share.ShowMessage('I0007', '保存');
									}
								}
							});
						}
					}
					//编辑并保存
					else if (button.id == 'report-edit-edit') {
						if (!isCanSave) {
							return;
						}
						if (!Ext.getCmp('report-all-info').getForm().isValid()) {
							return;
						}
						var grid = Ext.getCmp('tab-report-report').getSelectionModel().getSelection()[0];
						var report_hid = grid.get('report_hid');
						//表名
						var table_name = Ext.getCmp('report-table').getValue();
						//模板名称
						var report_name = Ext.getCmp('report-name').getValue();
						//报告描述
						var report_describe = Ext.getCmp('report-describe').getValue();
						//过滤条件
						var filter_condition = '';
						//遍历过滤条件
						for (var i = 1; i <= myId; i++) {
							var flag = Ext.getCmp('filter_field' + i).isVisible();
							//过滤字段
							var filterfield = Ext.getCmp('filter_field' + i).getValue() == null ? '' : Ext.getCmp('filter_field' + i).getValue();
							//运算符
							var filteroperator = Ext.getCmp('operator' + i).getValue() == null ? '' : Ext.getCmp('operator' + i).getValue();
							//过滤值
							var filtervalueval = Ext.getCmp('filter_value' + i).getValue();
							if (flag) {
								if (!filterfield == '' && !filteroperator == '' && !filtervalueval == ''){
									var filtervalue = '';
									//当过滤条件选择包含时直接在数据库中存入like，方便报告查看使用
									if (filteroperator == 'like') {
										filtervalueval = "'%" + filtervalueval + "%'";
									} else {
										filtervalueval = "'" + filtervalueval + "'";
									}
									filtervalue += filtervalueval;
									if (i > 1) {
										filter_condition += ';';
									}
									filter_condition += filterfield + ',' +  filteroperator + ',' + filtervalue;
								} else if (!filterfield == '' && filteroperator == '' && filtervalueval == '') { // 1
									Ext.getCmp('operator' + i).markInvalid(Share.T('此项目不能为空。'));
									Ext.getCmp('filter_value' + i).markInvalid(Share.T('此项目不能为空。'));
									return;
								} else if (!filterfield == '' && !filteroperator == '' && filtervalueval == '') { // 2
									Ext.getCmp('filter_value' + i).markInvalid(Share.T('此项目不能为空。'));
									return;
								} else if (!filterfield == '' && filteroperator == '' && !filtervalueval == '') { // 3
									Ext.getCmp('operator' + i).markInvalid(Share.T('此项目不能为空。'));
									return;
								} else if (!filteroperator == '' && filterfield == '' && filtervalueval == '') { // 4
									Ext.getCmp('filter_field' + i).markInvalid(Share.T('此项目不能为空。'));
									Ext.getCmp('filter_value' + i).markInvalid(Share.T('此项目不能为空。'));
									return;
								} else if (!filteroperator == '' && filterfield == '' && !filtervalueval == '') { // 5
									Ext.getCmp('filter_field' + i).markInvalid(Share.T('此项目不能为空。'));
									return;
								} else if (!filtervalueval == '' && filterfield == '' && filteroperator == '') { // 6
									Ext.getCmp('filter_field' + i).markInvalid(Share.T('此项目不能为空。'));
									Ext.getCmp('operator' + i).markInvalid(Share.T('此项目不能为空。'));
									return;
								} else if (filterfield == '' && filteroperator == '' && filtervalueval == ''){
									continue;
								}
							} else {
								continue;
							}
						}
						if (filter_condition.substring(0,1) == ';') {
							filter_condition = "\"" + filter_condition.substring(1,filter_condition.length) + "\"";
						} else {
							filter_condition = "\"" + filter_condition + "\"";
						}
						//判断无过滤条件是将filter_condition赋值为空
						if (Ext.getCmp('filter_field1').getValue() == null || Ext.getCmp('filter_field1').getValue() == '') {
							filter_condition = null;
						}
						//显示字段
						var table_field = "\"";
						table_field += Ext.getCmp('table_field').getValue();
						table_field += "\"";
						var user_id = "\"";
						user_id += Ext.getCmp('user').getValue();
						user_id += "\"";
						//当saveoredit为0时，说明之前没有点击另存为按钮，执行修改方法
						if (saveoredit == 0) {
							Share.AjaxRequest({
								url : ctx + '/ReportEditEdit',
								params : {
									report_hid : report_hid,
									table_name : table_name,
									report_name : report_name,
									report_describe : report_describe,
									filter_condition : filter_condition,
									table_field : table_field,
									user_id : user_id
								},
								callback : function(json) {
									if (json.resultcode == '0') {
										Ext.getCmp('win-reporteditpanel').close();
										Share.ShowMessage('I0006', '编辑');
										Ext.getCmp('tab-report-report').getStore().reload();
									}else{
										Share.ShowMessage('E0006', '编辑');
									}
								}
							});
						} else {
							//点击过另存为按钮执行保存方法
							Share.AjaxRequest({
								url : ctx + '/ReportEditSave',
								params : {
									table_name : table_name,
									report_name : report_name,
									report_describe : report_describe,
									filter_condition : filter_condition,
									table_field : table_field,
									user_id : user_id
								},
								callback : function(json) {
									if (json.resultcode == '0') {
										Ext.getCmp('win-reporteditpanel').close();
										Share.ShowMessage('I0006', '另存为');
										Ext.getCmp('tab-report-report').getStore().reload();
									} else {
										Share.ShowMessage('I0007', '另存为');
									}
								}
							});
						}
						saveoredit = 0;
					} else if(button.id == 'addbtn') {
						//过滤条件添加函数
						addcondition();
					}
					//创建并显示选择用户组窗口
					else if (button.id == 'getusergroup') {
						Ext.create('Ext.window.Window', {
						    title: Share.T('选择用户组'),
						    id:'user-group-win',
						    height : 300,
						    width : 400,
						    modal :true,
						    layout : {
								type : 'absolute'
							},
						    items: [{
						        xtype : 'grid',
						        id : 'user_group',
						        height : 230,
						        border : false,
						        autoScroll : true,
						        columns : [{
				                    xtype : 'gridcolumn',
				                    width : 340,
				                    align : 'left', 
				                    dataIndex : 'text',
				                    text : Share.T('用户组'),
				                    valueField : 'value',
									displayField : 'text'
				                }],
						        viewConfig: {
						        	enableTextSelection:true
						        },
						        selModel: Ext.create('Ext.selection.CheckboxModel', {
					            	checkOnly: false
								}),
					            store : new Ext.data.JsonStore({
					            	proxy: { 
					            		type : 'ajax', 
				            	        url : ctx + '/getusergroup',
				            	        params : {},
				            	        reader : { 
				            	            type : 'json',
				            	            totalProperty : '',
				            	            root : '' 
				            	         	} 
				            	        },
				            	    fields : ['text','value'], 
				            	    autoLoad : true 
								    }),
								valueField : 'value',
								displayField : 'text'
						    },{
						    	xtype : 'button',
						    	id : 'user-group-yes',
						    	x : 250,
						    	y : 240,
						    	width : 50,
						    	text : Share.T('确定')
						    },{
						    	xtype : 'button',
						    	id : 'user-group-cancel',
						    	x : 310,
						    	y : 240,
						    	width : 50,
						    	text : Share.T('取消')
						    }]
						}).show();
					}
					//选择用户组
					else if(button.id == 'user-group-yes') {
				    	
				    	var grid = Ext.getCmp('user_group');
						if (grid == undefined) {
							return;
						}
						var selModel = grid.getSelectionModel();
						if (selModel.hasSelection()) {
							var row = selModel.getSelection();
							var user_group = "";
			                for(i = 0, len = row.length; i < len; i++){
			                	user_group += row[i].get("text");
			                	if(i < len - 1){
			                		user_group += ",";
			                	}
			                }
			                user_group += "";
							Share.AjaxRequest({
								url : ctx + '/getUserIdOfGroup',
								params : {
									user_group : user_group
								},
								callback : function(json) {
									//给用户itemselector赋值，值为用户id，格式为setValue(1,2,3,4,5)
									var selectuser = Ext.getCmp('user').getValue();
									var useradd = ',';
									if (selectuser == '') {
										Ext.getCmp('user').setValue(json);
									} else {
										useradd += selectuser;
										Ext.getCmp('user').setValue(json += useradd);
									}
									Ext.getCmp('user-group-win').close();
								}
							});
						} else {
							Share.ShowMessage('I0011', '一组用户');
							return;
						}
					}
					//关闭选择用户组窗口
					else if (button.id == 'user-group-cancel') {
						Ext.getCmp('user-group-win').close();
					}
					//报告查看导出按钮
					else if (button.id == 'report_export') {
						var report_hid = Ext.getCmp('hidden_report_hid').getValue();
						window.open(ctx+'/defineReportExport?report_hid= ' + report_hid);
					}
				}
			}
		});
	}
});